package com.itrh.org.controller;

import com.itrh.base.annotation.AuthPermission;
import com.itrh.org.query.DepartmentQuery;
import com.itrh.org.util.Result;
import com.itrh.org.domain.Department;
import com.itrh.org.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * ClassName: DepartController
 *
 * @author XHU_WHY
 * @version V1.0
 * @since 2024/3/29 14:21
 */
@RestController
@RequestMapping("/dept")
@Api(tags = "部门管理", description = "关于部门API接口")
@AuthPermission(name = "部门管理")
public class DepartmentController {
    @Resource
    private IDepartmentService departmentService;

    @PutMapping
    @ApiOperation(value = "通过ID查询")
    @AuthPermission(name = "添加/修改部门")
    public Result saveOrUpdate(@RequestBody @ApiParam(name = "部门信息", required = true, value = "ID为空新增，不为空修改") Department department) {
        return departmentService.saveOrUpdate(department);
    }

    @GetMapping
    @AuthPermission(name = "查询部门列表")
    public Result list() {
        return departmentService.selectAll();
    }

    @PostMapping
    @AuthPermission(name = "条件分页查询部门列表")
    public Result pageList(@RequestBody DepartmentQuery query) {
        return departmentService.pageList(query);
    }

    @GetMapping("/{id}")
    @AuthPermission(name = "通过ID查询部门")
    public Result getById(@PathVariable @ApiParam(name = "部门ID", required = true) Long id) {
        return departmentService.selectById(id);
    }

    @DeleteMapping("/{id}")
    @AuthPermission(name = "通过ID删除部门")
    public Result deleteById(@PathVariable @ApiParam(name = "部门ID", required = true) Long id) {
        return departmentService.deleteById(id);
    }

    @GetMapping("/tree")
    @AuthPermission(name = "获取部门树")
    public Result getTree() {
        return departmentService.getTree();
    }
}
